const CryptoJS = require("crypto-js");
const moment = require('moment');

module.exports = {
    userMsg: function (ctx) {
        let token = ctx.request.headers.token;
        if (!token) {
            return ctx.helper.getErrorMsg(201);
        }
        let cry_obj = CryptoJS.AES.decrypt(token, 'sharesites');
        let info_obj = cry_obj.toString(CryptoJS.enc.Utf8);
        let create_real_obj = JSON.parse(JSON.stringify(info_obj));
        create_real_obj = JSON.parse(create_real_obj);
        return create_real_obj;
    },
    isTimeOut: async function (app, user_token) {
        try {
            let date = moment(user_token.time, 'YYYY-MM-DD HH:mm:ss');
            let nowDate = moment();
            let diff = nowDate.diff(date, 'days');
            let user_role_over_time = await app.redis.hget('overTime', user_token.roleId);
            if (diff >= user_role_over_time) {
                return true;
            } else {
                return false;
            }

        } catch (data) {
            console.log(data);
        }

    }
}